# You can do "make SUB=blah" to make only a few, or edit here, or both
# You can also run make directly in the subdirs you want.

SUB =   lib common tftp tftpd

%.build: config/MCONFIG config/config.h version.h
	$(MAKE) -C $(patsubst %.build, %, $@)

%.install: config/MCONFIG config/config.h version.h
	$(MAKE) -C $(patsubst %.install, %, $@) install

%.clean:
	$(MAKE) -C $(patsubst %.clean, %, $@) clean

%.distclean:
	$(MAKE) -C $(patsubst %.distclean, %, $@) distclean

all:      config/MCONFIG $(patsubst %, %.build, $(SUB))

tftp.build: lib.build common.build
tftpd.build: lib.build common.build

install:  config/MCONFIG $(patsubst %, %.install, $(SUB))

clean:	localclean $(patsubst %, %.clean, $(SUB))

localclean:
	rm -f version.h

distclean: localdistclean $(patsubst %, %.distclean, $(SUB))

localdistclean: localclean
	rm -f config/config/MCONFIG config.status config.log config/config.h *~ \#*
	rm -rf *.cache
	find . -type f \( -name \*.orig -o -name \*.rej \) | xargs rm -f

spotless: distclean
	rm -f configure config/config.h.in tftp.spec

autoconf: configure config/config.h.in

config:	config/MCONFIG config/config.h

release:
	$(MAKE) autoconf
	$(MAKE) tftp.spec
	$(MAKE) distclean

config/MCONFIG: configure config/MCONFIG.in config/config.h.in
	if test -x config.status; then \
		./config.status --recheck && ./config.status ; \
	else \
		./configure ; \
	fi

config/config.h: config/MCONFIG
	: Generated by side effect

configure: configure.ac
	sh autogen.sh

config/config.h.in: configure
	: Generated by side effect

version.h: version
	echo \#define VERSION \"tftp-hpa `cat version`\" > version.h

tftp.spec: tftp.spec.in version
	sed -e "s/@@VERSION@@/`cat version`/g" < $< > $@ || rm -f $@
